<template>
    <div class="Singer">
        <div class="left" ref="left" @scroll="scrollfn">
            <div class="content" v-for="item in englishsinger" :key="item.type" ref="con">
                <div class="title"><h2>{{ item.type }}</h2></div>
                <ul>
                    <li v-for="val in item.children" :key="val.Fsinger_name" @click="setsinger(val)">
                    <div class="singerjpg">
                        <img
                            :src="`${imgstr}${val.Fsinger_mid}.jpg?max_age=2592000`"
                            alt=""
                        />
                        <span>{{ val.Fsinger_name }}</span>
                    </div>
                    </li>
                </ul>
            </div>       
        </div>
        <div class="right">
            <ul v-for="(item,index) in englishsinger" :key="index">
                <li :class="{active:curindex===index}" @click="change(index)">
                    {{ item.type }}
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import { mapMutations } from 'vuex'
import { getSingerList, getSingerDetail } from "@/api/singer.js";
export default {
    data() {
        return {
        getsingerList: [],
        englishsinger: [
            {
            type: "A",
            children: [],
            },
            {
            type: "B",
            children: [],
            },
            {
            type: "C",
            children: [],
            },
            {
            type: "D",
            children: [],
            },
            {
            type: "E",
            children: [],
            },
            {
            type: "F",
            children: [],
            },
            {
            type: "G",
            children: [],
            },
            {
            type: "H",
            children: [],
            },
            {
            type: "I",
            children: [],
            },
            {
            type: "J",
            children: [],
            },
            {
            type: "K",
            children: [],
            },
            {
            type: "L",
            children: [],
            },
            {
            type: "M",
            children: [],
            },
            {
            type: "N",
            children: [],
            },
            {
            type: "O",
            children: [],
            },
            {
            type: "P",
            children: [],
            },
            {
            type: "Q",
            children: [],
            },
            {
            type: "R",
            children: [],
            },
            {
            type: "S",
            children: [],
            },
            {
            type: "T",
            children: [],
            },
            {
            type: "U",
            children: [],
            },
            {
            type: "V",
            children: [],
            },
            {
            type: "W",
            children: [],
            },
            {
            type: "X",
            children: [],
            },
            {
            type: "Y",
            children: [],
            },
            {
            type: "Z",
            children: [],
            },
        ],
        curindex: 0,
        listTop: [],
        imgstr: 'https://y.gtimg.cn/music/photo_new/T001R300x300M000',
        };
    },
    mounted() {
        getSingerList().then((res) => {
            this.getsingerList = res.data.list;
            this.englishsinger.forEach((val) => {
                let qwe = this.getsingerList;
                val.children = qwe.filter((item) => {
                return (item.Findex === val.type);
                });
            });
            this.$nextTick(()=>{
                this.listTop = this.$refs.con.map(con => con.offsetTop);
            })
        });
    },
    methods: {
        ...mapMutations(['setPublicAlertFlag', 'setimg', 'getalertlist']),
        change(index){
            this.curindex = index;
            this.$refs.left.scrollTop = this.$refs.con[index].offsetTop;
        },
        scrollfn(){
            this.listTop.forEach((val,index) => {
                if(this.$refs.left.scrollTop >= val){
                    this.curindex = index;
                }
            })
        },
        async setsinger(item, i){
            this.setimg(`${this.imgstr}${item.Fsinger_mid}.jpg`)
            this.setPublicAlertFlag(true)
            let res = await getSingerDetail(item.Fsinger_mid)
            this.getalertlist(res.data.list)
        }
    }
};
</script>

<style lang="scss" scoped>
.Singer {
    width: 100%;
    overflow: auto;
    background: #222222;
    position: fixed;
    top: 88px;
    bottom: 0;
}
.content {
    display: flex;
    flex-direction: column;  
}
.title {
    height: 30px;
    width: 100%;
    background: #333333;
    padding-left: 20px;
    h2 {
        font-size: 12px;
        color: #ffffff80;
        line-height: 30px;
    }
}
li {
    flex: 1;
    height: 70px;
    img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        vertical-align: middle;
    }
    .singerjpg {
        padding: 20px 0 0 30px;
    }
    span {
        color: #ffffff80;
        line-height: 50px;
        margin-left: 20px;
        display: inline-block;
    }
}
.left{
    overflow: auto;
    height: 100%;
    width: 100%;
    scroll-behavior: smooth;
}
.right {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff80;
    z-index: 20;
    text-align: center;
    font-family: Helvetica;
    ul {
        width: 20px;
        background: #181818;
        /deep/ li {
            color: #ffffff80;
            height: 18px;
            width: 20px;
            font-size: 12px;
            padding: 3px;
            &.active{
                color: #ffcd32; 
            }
        }
    }
}
</style>